extends Node

signal sword_upgrade(upgrade: AbilityUpgrade, current_upgrade: Dictionary)
signal axe_upgrade(upgrade: AbilityUpgrade, current_upgrade: Dictionary)


func _ready() -> void:
	GameEvents.ability_upgrade_added.connect(set_ability)
	pass


func set_ability(upgrade: AbilityUpgrade, current_upgrade: Dictionary) -> void:
	if upgrade.id == "sword_rate" || upgrade.id == "sword_damage":
		sword_upgrade.emit(upgrade, current_upgrade)
	elif upgrade.id == "axe":
		if upgrade is Ability:
			self.add_child(upgrade.ability_controller_scene.instantiate())
			GameEvents.emit_ability_get_axe()
	elif upgrade.id == "axe_damage":
		axe_upgrade.emit(upgrade, current_upgrade)
	elif upgrade.id == "player_speed":
		var speed = self.get_parent().SPEED
		self.get_parent().speed = speed * (1 + current_upgrade[upgrade.id]["quantity"] * .1)
